﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.LanguageExtensions
{
	internal static class WinRTStreamExtensions
	{
		public static void FormattedWrite(this Stream stream, string format, params object[] parameters)
		{
			if (stream != null)
			{
				Write(stream, string.Format(format, parameters));
			}
		}

		public static void Write(this Stream stream, object objectOut)
		{
			if (stream != null && objectOut != null)
			{
				string outString = objectOut as string;

				if (string.IsNullOrEmpty(outString))
				{
					outString = objectOut.ToString();
				}

				byte[] outBytes = Encoding.UTF8.GetBytes(outString);

				stream.Write(outBytes, 0, outBytes.Count());
			}
		}

		public static void WriteLine(this Stream stream, object objectOut)
		{
			if (stream != null)
			{
				Write(stream, objectOut);

				Write(stream, Environment.NewLine);
			}
		}
	}
}